package com.ynet.middleground.riskmanage.mq.producer;

import com.ynet.core.log.IfpLogger;
import com.ynet.middleground.riskmanage.mq.WorldexCustomerAnalyticsZt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author songyf
 * @description 中台需要推送的全球捷运客户分析数据
 * @date 2021-10-19
 */
@EnableBinding({WorldexCustomerAnalyticsZt.class})
@Component
public class WorldexCustomerAnalyticsProducer {

    @Autowired
    private WorldexCustomerAnalyticsZt worldexCustomerAnalyticsZt;

    /**
     * 给核心系统 MQ 推送客户分析数据
     *
     * @param data 推送客户分析数据
     */
    public void sendMessagesCustomerAnalytics(Map<String, Object> data) {
        IfpLogger.info("mq", "MQ 推送全球捷运客户分析数据给核心系统，往 Binding-{} 推送信息-{}", WorldexCustomerAnalyticsZt.JKZTFK_TO_BLXD_KHSJFX, data);
        Map<String, Object> headers = new HashMap<>(1);
        // tags 标签对应 yml 配置文件
        headers.put("TAGS", "in");
        MessageHeaders messageHeaders = new MessageHeaders(headers);
        Message<Map<String, Object>> message = MessageBuilder.createMessage(data, messageHeaders);
        this.worldexCustomerAnalyticsZt.notice().send(message);
    }

    /**
     * 给核心系统 MQ 推送客户全量数据
     *
     * @param data 推送客户全量数据
     */
    public void sendMessagesCustomerAll(Map<String, Object> data) {
        IfpLogger.info("mq", "MQ 推送全球捷运客户全量数据给核心系统，往 Binding-{} 推送信息-{}", WorldexCustomerAnalyticsZt.JKZTFK_TO_BLXD_QLKHMD, data);
        Map<String, Object> headers = new HashMap<>(1);
        // tags 标签对应 yml 配置文件
        headers.put("TAGS", "in");
        MessageHeaders messageHeaders = new MessageHeaders(headers);
        Message<Map<String, Object>> message = MessageBuilder.createMessage(data, messageHeaders);
        this.worldexCustomerAnalyticsZt.noticeAll().send(message);
    }
}
